package com.heima.behavior.controller;

import com.heima.behavior.service.IApBehaviorService;
import com.heima.model.behavior.dtos.ArticleInfoDto;
import com.heima.model.behavior.dtos.BehaviorDto;
import com.heima.model.behavior.dtos.CollectionBehaviorDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.utils.common.WmThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/v1")
public class behaviorController {
    @Autowired
    private IApBehaviorService apBehaviorService;
    @PostMapping("/likes_behavior")
    public ResponseResult likesBehavior(@RequestBody BehaviorDto dto){
        log.info("收到点赞行为{}",dto);
        apBehaviorService.saveLikesBehavior(dto);
        return ResponseResult.okResult(WmThreadLocalUtil.getUser().getId());
    }
    @PostMapping("/read_behavior")
    public ResponseResult readBehavior(@RequestBody BehaviorDto dto){
        log.info("收到阅读行为{}",dto);
        apBehaviorService.saveReadBehavior(dto);
        return ResponseResult.okResult(null);
    }
    @PostMapping("/un_likes_behavior")
    public ResponseResult unLikesBehavior(@RequestBody BehaviorDto dto){
        log.info("收到不喜欢行为{}",dto);
        apBehaviorService.saveUnLikesBehavior(dto);
        return ResponseResult.okResult(WmThreadLocalUtil.getUser().getId());
    }
    @PostMapping("/collection_behavior")
    public ResponseResult collectionBehavior(@RequestBody CollectionBehaviorDto dto){
        log.info("收到收藏行为{}",dto);
        apBehaviorService.saveCollectionBehavior(dto);
        return ResponseResult.okResult("ok");
    }
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto){
        log.info("收到加载文章行为{}",dto);
        return ResponseResult.okResult(apBehaviorService.loadArticleBehavior(dto));
    }
}
